<?php

require_once '../config.php';
require_once '../functions.php';

books_get_current_user();
function make_add()
{
    if (empty($_POST['description'])) {
        $GLOBALS['message']="描述";
    }
    
    if (empty($_POST['authors'])) {
        $GLOBALS['message']="作者简介";
    }
    if (empty($_POST['link'])) {
        $GLOBALS['message']="链接";
    }
    if (empty($_POST['discussnum'])) {
        $GLOBALS['message']="支持";
    }
    if (empty($_POST['ISBN'])) {
        $GLOBALS['message']="请填写日期";
    }


    $description= $_POST['description'];
    $authors= $_POST['authors'];
    $link=$_POST['link'];
    $discussnum=$_POST['discussnum'];
    $ISBN=$_POST['ISBN'];
    $rows = book_execute("insert into options values (null, '{$description}', '{$authors}','{$link}','{$discussnum}','{$ISBN}')");
    var_dump($rows);
    
    $GLOBALS['success'] = $rows > 0;
    $GLOBALS['message'] = $rows <= 0 ? '添加失败！' : '添加成功！';

    header('Location: /admin/substance.php');
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    make_add();
}


?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Users &laquo; Admin</title>
  <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/static/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="/static/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="/static/assets/css/admin.css">
  <script src="/static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
  <?php include 'inc/navbar_admin.php'; ?>
    <div class="container-fluid">
        <div class="col-md-6">
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">


            <div class="form-group">
              <label for="description">描述</label>
              <textarea class="form-control" name="description" id="description" cols="30" rows="10" placeholder="描述"></textarea>
            </div>
            <div class="form-group">
              <label for="authors">作者</label>
              <textarea class="form-control" name="authors" id="authors" cols="30" rows="10" placeholder="作者"></textarea>
            </div>
            <div class="form-group">
              <label for="link">链接</label>
              <input class="form-control" type="text" name="link" id="link" >
            </div>
            <div class="form-group">
              <label for="link">支持</label>
              <input class="form-control" type="text" name="discussnum" id="discussnum" >
            </div>
            <div class="form-group">
              <label for="link">isbn</label>
              <input class="form-control" type="text" name="ISBN" id="ISBN" >
            </div>
            <div class="form-group">
            <button class="btn btn-primary" type="submit">保存</button>
              <a href="/admin/test1.php" class="btn btn-primary" type="submit">返回</a>
            </div>
          </form>
        </div>
    </div>
  </div>
  <?php include 'inc/sidebar.php'; ?>
  <?php $current_page = 'book'; ?>

  <script src="/static/assets/vendors/jquery/jquery.js"></script>
  <script src="/static/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
</body>
</html>
